/**
 * LawDataTagServiceImpl.java
 * @author
 * 作者 屈甲康 
 */
package org.jackysoft.service.impl;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.OfficeDataRegion;
import org.jackysoft.service.AbstractStringIdServiceImpl;
import org.jackysoft.service.OfficeDataRegionService;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class OfficeDataRegionServiceImpl extends AbstractStringIdServiceImpl<OfficeDataRegion>
implements OfficeDataRegionService {
    /**
	 * 
	 */
	private static final long serialVersionUID = 3740898367692190240L;
	final static Log logger = LogFactory.getLog(OfficeDataRegionServiceImpl.class);

	public OfficeDataRegionServiceImpl(){	   
	    super(OfficeDataRegion.class);
	}

	@Override
	public Collection<OfficeDataRegion> getDataRegionsByWorkflow(long beanId)
			throws DataAccessException {
		String hql = HQL("from %s t where t.workflowId=%d",entitytable(),beanId);
		List list = query(hql).list();
		return list;
	}

	@Override
	public Collection<OfficeDataRegion> getDataRegionsByProcess(String pname)
			throws DataAccessException {
		String hql = HQL("from %s t where t.workflow='%s'",entitytable(),pname);
		List list = query(hql).list();
		return list;
	}

	@Override
	public void removeOfficeDataRegionsByWorkflow(long contractId)
			throws DataAccessException {
		String hql = HQL("delete from %s  where workflowId=%d",entitytable(),contractId);
		query(hql).executeUpdate();
		
	}

	@Override
	public void removeOfficeDataRegionsByName(String contractId)
			throws DataAccessException {
		String hql = HQL("delete from %s  where workflow='%s'",entitytable(),contractId);
		query(hql).executeUpdate();
		
	}

	@Override
	public String getValue(long workflow, String name)
			throws DataAccessException {
		String hql = HQL("select d.value from %s d where d.workflowId=%d and d.name='%s'",entitytable(),workflow,name);
		Iterator itr = query(hql).iterate();
		return (String) (itr.hasNext()?itr.next():null);
	}	
		
}